<template>
  <el-dialog
    :title="IdRulesTitle"
    :visible.sync="IdRulesDialogVisible"
    width="30%"
    :before-close="handleCloseIdRules"
    @close="closeDialog"
    :close-on-click-modal="false"
  >
    <div>
      <el-form ref="IdRulesForm" :rules="IdRules" :model="IdRulesForm" label-width="110px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="规则名称" prop="authenticateName">
              <el-input v-model="IdRulesForm.authenticateName" placeholder="请输入规则名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="所属分类" prop="cate">
              <el-input disabled v-model="IdRulesForm.cate"></el-input>
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>

          <el-col :span="12">
            <el-form-item label="处理模式" prop="pattern">
              <el-select v-model="IdRulesForm.pattern" placeholder="请选择处理模式">
                <el-option label="条件过滤" value="0"></el-option>
                <el-option label="敏感词过滤" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="IdRulesForm.pattern === '1' ? '敏感词过滤' : '过滤条件'" prop="patternText">
              <div  v-if="IdRulesForm.pattern === '1'">
                <el-input v-model="IdRulesForm.patternText" placeholder="请输入内容"></el-input>
              </div>
              <div v-else>
                <el-popover
                  placement="bottom"
                  width="600"
                  trigger="click">
                    <searchFilters
                      :filter1="filter1"
                      :filter2="filter2"
                      :filter4="filter4"
                      btn1="保存"
                      btn2="清空"
                      @getSave="getSave"
                    />
                  <el-input disabled slot="reference" v-model="IdRulesForm.patternText" placeholder="请选择过滤条件"></el-input>
                </el-popover>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="处理类型" prop="patternType">
              <el-select v-model="IdRulesForm.patternType" placeholder="请选择处理类型">
                <el-option label="自动鉴定" value="0"></el-option>
                <el-option label="建议鉴定" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="建议公开范围" prop="scope">
              <el-select v-model="IdRulesForm.scope" placeholder="请选择建议公开范围">
                <el-option
                  v-for="(item,index) in scopeList"
                  :key="index"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="建议密级" prop="securityLevel">
              <el-select v-model="IdRulesForm.securityLevel" placeholder="请选择建议密级">
                <el-option
                  v-for="(item,index) in securityList"
                  :key="index"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否启用" prop="isOpen">
              <el-radio-group v-model="IdRulesForm.isOpen">
                <el-radio label="1">是</el-radio>
                <el-radio label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="建议保管期限" prop="keepTime">
              <!-- <el-date-picker
                v-model="IdRulesForm.keepTime"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
              /> -->
              <el-select v-model="IdRulesForm.keepTime" placeholder="请选择保管期限">
                <el-option
                  v-for="(item,index) in timeRange"
                  :key="index"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="描述">
          <el-input type="textarea" v-model="IdRulesForm.remark"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="IdRulesConfirm">确 定</el-button>
      <el-button @click="handleCloseIdRules">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import searchFilters from '@/components/searchFilters'
import { addIdRules, updateIdRules } from '@/api/system/sort'
export default {
  name: 'IdRulesDialog',
  props:['IdRulesForm','IdRulesDialogVisible','IdRulesTitle','queryParams','scopeList','securityList','filter1','filter2','filter4','getIdRulesList', 'timeRange'],
  components:{
    searchFilters
  },
  data(){
    return {
      IdRules:{
        authenticateName: [
          { required: true, message: '请输入活动名称', trigger: 'blur' },
        ],
        pattern: [
          { required: true, message: '请选择处理模式', trigger: 'blur' },
        ],
        patternType: [
          { required: true, message: '请输入处理类型', trigger: 'blur' },
        ],
        patternText: [
          { required: true, message: '请选择过滤条件或者敏感词', trigger: 'blur' },
        ],
        scope: [
          { required: true, message: '请输入建议公开范围', trigger: 'blur' },
        ],
        securityLevel: [
          { required: true, message: '请输入建议密级', trigger: 'blur' },
        ],
        isOpen: [
          { required: true, message: '请选择是否启用', trigger: 'blur' },
        ],
        keepTime: [
          { required: true, message: '请输入建议保管期限', trigger: 'blur' },
        ]
      },
    }
  },
  methods:{
    closeDialog(){
      for (const key in this.IdRulesForm) {
        this.IdRulesForm[key] = ''
      }
    },
    handleCloseIdRules(){
      this.$emit('closeIdRules')
    },
    // 子组件传递的过滤条件数据
    getSave(str,a,val){
      this.IdRulesForm.patternText = val
    },
    // 新增鉴定规则
    IdRulesConfirm(){
      this.$refs.IdRulesForm.validate(async(valid) => {
        if (!valid) {
          return
        }
        this.$confirm('确认提交吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // this.IdRulesForm.keepTimeBegin = this.IdRulesForm.keepTime[0]
          // this.IdRulesForm.keepTimeEnd = this.IdRulesForm.keepTime[1]
          this.IdRulesForm.sortNo = this.queryParams.sortPrantNo
          if(this.IdRulesTitle === '新增鉴定规则'){
            delete this.IdRulesForm.params
            this.add()
            this.getIdRulesList(this.IdRulesForm.sortNo)
          }else {
            this.update()
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消提交'
          });
        });
      })
    },
    async add(){
      const res = await addIdRules(this.IdRulesForm)
      if(res.code === 200){
        this.$message.success(res.msg)
        this.handleCloseIdRules()
      }
    },
    async update(){
      const res = await updateIdRules(this.IdRulesForm)
      if(res.code === 200){
        this.$message.success(res.msg)
        this.handleCloseIdRules()
        //  获取列表
        this.getIdRulesList()
      }
    }
  },
  watch:{
  },
}
</script>

<style lang="scss" scoped>


</style>
